package b59;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main3 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String s = bf.readLine();
        String[] split = s.split("#");
        String[] s1 = split[0].split(",");
        int N = Integer.parseInt(split[1]);
        int[] num = new int[s1.length];
        for (int i = 0; i < s1.length; i++) {
            num[i] = Integer.parseInt(s1[i]);
        }
        int i = find(num, N);
        System.out.println(i);


    }

    public static int find(int[] num,int N){
        int max = 0;
        int ass = 0;
        for (int i = 0; i < num.length; i++) {
            max = Math.max(max,num[i]);
        }
        Arrays.sort(num);
        for (int i = max; i <10000 ; i++) {
            int res = 0;
            for (int j = 0; j < num.length; ) {
                int temp = num[j];
                while(temp<=i){
                    j++;
                    if(j==num.length){
                        break;
                    }else{
                        temp += num[j];
                    }
                }
                res ++;
            }
            if(res <= N){
                ass = i;
                break;
            }
        }return ass;
    }
}
